package my;

import my.sort.BucketSort;
import my.sort.CountingSort;
import my.sort.RadixSort;
import my.sort.Sort;
import my.sort.cmp.BubbleSort;
import my.sort.cmp.HeapSort;
import my.sort.cmp.InsertionSort;
import my.sort.cmp.MergeSort;
import my.sort.cmp.QuickSort;
import my.sort.cmp.SelectionSort;
import my.sort.cmp.ShellSort;
import utils.IntegerUtil;
import utils.Tools;

import java.util.Arrays;

/**
 * 测试
 *
 * @author AJun
 * @date 2020/9/15
 */
public class SortMain {

    public static void main(String[] args) {
        Integer[] array = IntegerUtil.random(20000, 1, 30000);
        testSorts(array,
                  new BubbleSort<>(),
                  new SelectionSort<>(),
                  new HeapSort<>(),
                  new InsertionSort<>(),
                  new MergeSort<>(),
                  new QuickSort<>(),
                  new ShellSort<>(),
                  new CountingSort(),
                  new RadixSort(),
                  new BucketSort()
        );
    }

    @SafeVarargs
    static void testSorts(Integer[] array, Sort<Integer>... sorts) {
        for (Sort<Integer> sort : sorts) {
            Integer[] newArray = IntegerUtil.copy(array);
            sort.sort(newArray); // 排序
            Tools.asserts(IntegerUtil.isAscOrder(newArray));
        }

        Arrays.sort(sorts);
        Arrays.stream(sorts).forEach(System.out::println);
    }

}
